package com.chapter16;

import java.util.Stack;

public class HanoiTower {

	private Stack<Integer> s1,s2,s3;
	
	private void initialize(int n){
		s1=new Stack<Integer>();
		s2=new Stack<Integer>();
		s3=new Stack<Integer>();
		for(int i=n;i>0;i--)
			s1.push(i);
	}
	public void solveTower(int n){
		initialize(n);
		solveTower(n,s1,s2,s3);
		System.out.println("size of s1=" + s1.size()+" "+"size of s2=" + s2.size()+" "+"size of s3=" + s3.size()+" ");
	}
	private void solveTower(int n,Stack<Integer> st1,Stack<Integer> st2,Stack<Integer> st3){
		if(n==0){
			st2.push(st1.pop());
			return;
		}
		solveTower(n-1,st1,st3,st2);
		st2.push(st1.pop());
		solveTower(n-1,st3,st2,st1);
	}
	
	public void testHanoi(int n){
		for(int i=1;i<n+1;i++)
			solveTower(i);
	}
}
